package cn.niit.pm.controller;

import cn.niit.pm.entity.Attendance;
import cn.niit.pm.entity.Train;
import cn.niit.pm.service.impl.TrainServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 培训管理
 * @author majiarui
 */
@Controller
@Api("培训管理")

public class TrainController {


    @Resource
    private TrainServiceImpl service;
    @GetMapping("/train")
    public String train(Train train,
                        @RequestParam(value = "pageSize", defaultValue = "0") int pageSize,
                        @RequestParam(value = "pageNumber", defaultValue = "10") int pageNumber, Model model){
        PageInfo info = service.select(train, pageSize, pageNumber);
        model.addAttribute("pageInfo", info);
        return "train_infor/train";
    }


    @PostMapping("/train/insert")
    @ResponseBody
    public void insert(Train train) {
        service.insert(train);
    }

    @PostMapping("/train/update")
    @ResponseBody
    public void save(Train train) {
        service.update(train);
    }

    @GetMapping("/train/delete/{id}")
    @ResponseBody
    public void delete(@PathVariable("id") Integer id) {
        service.delete(id);
    }

    @GetMapping("/train/selectById/{id}")
    @ResponseBody
    public Train selectById(@PathVariable("id") Long id) {
        return service.selectById(id);
    }

}
